package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.system.service.ISysSupplierService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysSuppliernper;
import com.ruoyi.system.service.ISysSuppliernperService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 供应商期数Controller
 * 
 * @author ruoyi
 * @date 2020-12-13
 */
@Controller
@RequestMapping("/system/suppliernper")
public class SysSuppliernperController extends BaseController
{
    private String prefix = "system/suppliernper";

    @Autowired
    private ISysSuppliernperService sysSuppliernperService;
    @Autowired
    private ISysSupplierService sysSupplierService;

    @RequiresPermissions("system:suppliernper:view")
    @GetMapping()
    public String suppliernper()
    {
        return prefix + "/suppliernper";
    }

    /**
     * 查询供应商期数列表
     */
    @RequiresPermissions("system:suppliernper:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysSuppliernper sysSuppliernper)
    {
        startPage();
        List<SysSuppliernper> list = sysSuppliernperService.selectSysSuppliernperList(sysSuppliernper);
        return getDataTable(list);
    }

    /**
     * 导出供应商期数列表
     */
    @RequiresPermissions("system:suppliernper:export")
    @Log(title = "供应商期数", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysSuppliernper sysSuppliernper)
    {
        List<SysSuppliernper> list = sysSuppliernperService.selectSysSuppliernperList(sysSuppliernper);
        ExcelUtil<SysSuppliernper> util = new ExcelUtil<SysSuppliernper>(SysSuppliernper.class);
        return util.exportExcel(list, "suppliernper");
    }

    /**
     * 新增供应商期数
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存供应商期数
     */
    @RequiresPermissions("system:suppliernper:add")
    @Log(title = "供应商期数", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysSuppliernper sysSuppliernper)
    {
        return toAjax(sysSuppliernperService.insertSysSuppliernper(sysSuppliernper));
    }

    /**
     * 修改供应商期数
     */
    @GetMapping("/edit/{supplierNperId}")
    public String edit(@PathVariable("supplierNperId") Long supplierNperId, ModelMap mmap)
    {
        SysSuppliernper sysSuppliernper = sysSuppliernperService.selectSysSuppliernperById(supplierNperId);
        mmap.put("sysSuppliernper", sysSuppliernper);
        return prefix + "/edit";
    }

    /**
     * 修改保存供应商期数
     */
    @RequiresPermissions("system:suppliernper:edit")
    @Log(title = "供应商期数", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysSuppliernper sysSuppliernper)
    {
        return toAjax(sysSuppliernperService.updateSysSuppliernper(sysSuppliernper));
    }

    /**
     * 删除供应商期数
     */
    @RequiresPermissions("system:suppliernper:remove")
    @Log(title = "供应商期数", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysSuppliernperService.deleteSysSuppliernperByIds(ids));
    }
    /**
     * 查询供应商详细
     */
    @RequiresPermissions("system:suppliernper:list")
    @GetMapping("/detail/{supplierNperId}")
    public String detail(@PathVariable("supplierNperId") Long supplierNperId, ModelMap mmap)
    {
        mmap.put("qishu", sysSuppliernperService.selectSysSuppliernperById(supplierNperId));
        mmap.put("suppliers", sysSuppliernperService.selectSysSuppliernperList(null));
        return "system/supplier/supplier";
    }
}
